home / software / tips and tricks / In SQL Server how to reseed table identity value ?

In SQL Server how to reseed table identity value ?

Updated:  03/26/2016 17:03 PM
Author:  Shiju Mathews

Status:    Resolved.


DBCC CHECKIDENT can reseed (reset) the identity value of the table. For example,a Table has 1025 rows with 1025 as last identity. If we want next record to have identity as 12500 we need to run following T SQL script in Query Analyzer.

DBCC CHECKIDENT ([your table Name], reseed, 2500);
DBCC CHECKIDENT ('tblProduct', reseed, 2500)



If table has to start with an identity of 1 with the next insert then table should be reseeded with the identity to 0. If identity seed is set below values that currently are in table, it will violate the uniqueness constraint as soon as the values start to duplicate and will generate error.

For self referencing tables truncate command will throw error when running 'TRUNCATE' command against it.

Cannot truncate table '[Table Name]' because it is being referenced by a FOREIGN KEY constraint.

On this situation we can delete all rows and then run the "DBCC CHECKIDENT" command.

DBCC CHECKIDENT ('tblProduct', reseed, 0)

Tags: In SQL Server how to reseed table identity value ?
Updated on: November 2024